<?php
require_once(dirname(dirname(__FILE__)).'/init.php');
require_once(ROOT_PATH.'service/WxpayAPI/lib/WxPay.Api.php');
require_once(ROOT_PATH.'service/WxpayAPI/example/WxPay.JsApiPay.php');
require_once(ROOT_PATH.'service/orders.php');

/**
* wxjsApi 微信orderApi
* shouxue
* 2017/10/26 
*/
class orderApi extends Base
{

	//初始化
	function __construct($Ioc)
	{
		//载入可访问区域
		$this->Method = array('cancelPay','check_pay');
		$this->Ioc 	  = $Ioc;
			
	}


    /**
     * Description: 主体服务
     * User: shouxue
     * Date: 2017/10/27
     */
    public function main($mode)
    {

        if (!$this->isMethod($mode)) {
            $this->Ioc->Response->Json(212, '请求服务不存在','',$this ->out_mode);
        }

        $data = array();
        //接入Api
        switch ($mode)
        {
            case "cancelPay":
                    $data  = $this ->order_cancel();
                 break;
            case "check_pay":
                    $data  = $this ->check_pay();
                 break;
            default:
                  
        }

        if (!$data && $data['code'] != 200) {
            $this->Ioc->Response->Json($data['code'], $data['msg'],'',$this ->out_mode);
        }

        $this->Ioc->Response->Json(200, '成功', $data,$this ->out_mode);
    }



	/**
	 * [order_cancel 支付取消]
	 * @Author   shouxue
	 * @DateTime 2017-11-01
	 * @version  v1.0
	 * @return   bool|mixed
	 */
	public function order_cancel(){

		$order_id  = isset($_REQUEST['order_id']) ? trim($_REQUEST['order_id'] ) : 0;
		if(!$order_id) {
          	return $this->Ioc->Response->Min(212, '订单号不能为空', $data); 
        }

		$orders = new orders($this->Ioc,$order_id);
		$mode   = 'order_cancel';
		$data   = $orders ->main($mode);
		
		return $data;
	}



  /**
   * [order_cancel 支付确认]
   * @Author   shouxue
   * @DateTime 2017-11-29
   * @version  v1.0
   * @return   bool|mixed
   */
  public function check_pay(){

    $order_id  = isset($_REQUEST['order_id']) ? trim($_REQUEST['order_id'] ) : 0;
    if(!$order_id) {
            return $this->Ioc->Response->Min(212, '订单号不能为空', $data); 
        }

    $orders = new orders($this->Ioc,$order_id);
    $data   = $orders ->check_pay();
    
    return $data;
  }


  
}

$mode     = trim($_REQUEST['mode']);
$orderApi = new orderApi($Ioc);
$orderApi ->main($mode); 
